package org.edu.modules.stu.stu.service.impl;

import org.edu.common.base.BasePageDto;
import org.edu.common.base.BaseServiceImpl;
import org.edu.common.dto.BaseCountDto;
import org.edu.common.utils.ConvertUtils;
import org.edu.common.base.BaseServiceImpl;
import org.edu.modules.stu.base.entity.VeBaseStudent;
import org.edu.modules.stu.base.service.VeBaseStudentService;
import org.edu.modules.stu.stu.mapper.VeStuPunishMapper;
import org.edu.modules.stu.stu.entity.VeStuPunish;
import org.edu.modules.stu.stu.dto.VeStuPunishDto;
import org.edu.modules.stu.stu.service.VeStuPunishService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;



/**
 * 实现类
 */
@Service
public class VeStuPunishServiceImpl extends BaseServiceImpl<VeStuPunish, VeStuPunishMapper> implements VeStuPunishService {

    @Autowired
    private VeBaseStudentService veBaseStudentService;

    public IPage<VeStuPunishDto> pageDto(BasePageDto page, @Param(Constants.WRAPPER) Wrapper queryWrapper){
        return mapper.pageDto(page,queryWrapper);
    }
    /**
    * 查询实体类
    */
    public VeStuPunishDto findDtoById(String id) {
        VeStuPunish entity = super.findById(id);
        VeStuPunishDto dto = ConvertUtils.convertToDto(entity, VeStuPunishDto.class);
        return dto;
    }

    /**
    * 新增或者修改
    */
    public void insertOrUpdate(VeStuPunishDto dto,Boolean isAdd){
        if(dto.getStuId()!=null) {
            VeBaseStudent baseStudent = veBaseStudentService.findById(dto.getStuId() + "");
            dto.setBjId(baseStudent.getBjId());
            dto.setBjText(baseStudent.getBjText());
            dto.setFalId(baseStudent.getFalId());
            dto.setSpecId(baseStudent.getSpecId());
            dto.setName(baseStudent.getXm());
            dto.setCode(baseStudent.getXh());
        }
        if(isAdd){
            super.insert(dto);
        }else{
            super.update(dto);
        }
    }

    @Override
    public List<BaseCountDto> countBy(Wrapper queryWrapper) {
        return mapper.countBy(queryWrapper);
    }

    @Override
    public void importExcel(List<Map<String, Object>> mapList){
        for (Map map: mapList) {
            VeStuPunishDto dto = new VeStuPunishDto();
                   //         dto.setStuId ((String)map.get(0000));
                   //         dto.setName ((String)map.get(0000));
                   //         dto.setCode ((String)map.get(0000));
                   //         dto.setFalId ((String)map.get(0000));
                   //         dto.setSpecId ((String)map.get(0000));
                   //         dto.setBjId ((String)map.get(0000));
                   //         dto.setTypeId ((String)map.get(0000));
                   //         dto.setPunishTime ((String)map.get(0000));
                   //         dto.setContent ((String)map.get(0000));
            
            super.insert(dto);
        }

    }

}
